package com.hellogood.work.evaluate.server.serviceImpl;

import java.text.DecimalFormat;
import java.util.List;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.hellogood.work.evaluate.server.common.MD5;
import com.hellogood.work.evaluate.server.dao.UserDAO;
import com.hellogood.work.evaluate.shared.po.User;
import com.hellogood.work.evaluate.shared.services.UserService;

public class UserServiceImpl extends RemoteServiceServlet implements UserService {

	private static final long serialVersionUID = 6162622679437157883L;

	@Override
	public User login(String username, String password) {
		UserDAO dao = new UserDAO();
		password = MD5.getMD5Str(password);
		return dao.login(username, password);
	}

	@Override
	public int getTotalNumber() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<User> getList() {
		UserDAO dao = new UserDAO();
		return dao.getList();
	}

	@Override
	public String modify(User user, boolean isModiy) {
		UserDAO dao = new UserDAO();
		if (!isModiy) {
			DecimalFormat df = new DecimalFormat("0000");
			int maxCode = Integer.valueOf(dao.getMaxCode());
			maxCode++;
			user.setUsercode(df.format(maxCode));
			String password = MD5.getMD5Str("888888");
			user.setPassword(password);
		}
		return dao.modify(user, isModiy);
	}

}
